#include "InternalConsole.h"
#include "internalconsolelua.h"
#include "LuaUtils.h"


void InternalConsoleLua::pushStaticFuncs(lua_State* L)
{
	static const struct luaL_Reg mylib [] = {
		{"Attach", li_attach},
		{"Detach", li_detach},
		{"AddPrinter", li_addPrinter},
		{"RemovePrinter", li_removePrinter},
		{"ExecuteCommand", li_executeCommand},
		{NULL, NULL}  /* sentinel */
	};

	// dump them into said table
	luaL_register(L, NULL, mylib);
}

int InternalConsoleLua::li_attach(lua_State* L)
{
	InternalConsole* op = (InternalConsole*)typeCheckUnboxAO(L,1,"InternalConsole");
	if(op == NULL){
		LOG(logERROR) << "Null self!";
	return 0;}
	int a1 = (int)lua_tointeger(L, 2);
	int a2 = (int)lua_tointeger(L, 3);
	op->attach(a1, a2);
	
	return 0;
}


int InternalConsoleLua::li_detach(lua_State* L)
{
	InternalConsole* op = (InternalConsole*)typeCheckUnboxAO(L,1,"InternalConsole");
	if(op == NULL){
		LOG(logERROR) << "Null self!";
	return 0;}
	op->detach();
	
	return 0;
}


int InternalConsoleLua::li_addPrinter(lua_State* L)
{
	InternalConsole* op = (InternalConsole*)typeCheckUnboxAO(L,1,"InternalConsole");
	if(op == NULL){
		LOG(logERROR) << "Null self!";
	return 0;}
	AnyAOPtr a1 = unboxAOPtr(L, 2);
	op->addPrinter(a1);
	
	return 0;
}


int InternalConsoleLua::li_removePrinter(lua_State* L)
{
	InternalConsole* op = (InternalConsole*)typeCheckUnboxAO(L,1,"InternalConsole");
	if(op == NULL){
		LOG(logERROR) << "Null self!";
	return 0;}
	AnyAOPtr a1 = unboxAOPtr(L, 2);
	op->removePrinter(a1);
	
	return 0;
}


int InternalConsoleLua::li_executeCommand(lua_State* L)
{
	InternalConsole* op = (InternalConsole*)typeCheckUnboxAO(L,1,"InternalConsole");
	if(op == NULL){
		LOG(logERROR) << "Null self!";
	return 0;}
	std::string a1 = lua_tostring(L, 2);
	op->executeCommand(a1);
	
	return 0;
}


